package pe.edu.upc.dsd.esb.whereeat.component.service;

import java.util.List;

import javax.jws.WebService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import pe.edu.upc.dsd.esb.whereeat.component.AbstractComponent;
import pe.edu.upc.dsd.whereeat.domain.Restaurant;
import pe.edu.upc.dsd.whereeat.service.RestaurantService;

@Component
@WebService
public class RestaurantServiceComponentImpl extends AbstractComponent implements
		RestaurantServiceComponent {

	private Logger logger = Logger
			.getLogger(RestaurantServiceComponentImpl.class);

	@Autowired
	private RestaurantService restaurantService;

	public int guardarRestaurant(Restaurant restaurant) {
		try {
			restaurantService.save(restaurant);
			return 1;
		} catch (Exception e) {
			logger.error(e);
		}
		return 0;
	}

	public int actualizarRestaurant(Restaurant restaurant) {
		try {
			restaurantService.update(restaurant);
			return 1;
		} catch (Exception e) {
			logger.error(e);
		}
		return 0;
	}

	public int eliminarRestaurant(Restaurant restaurant) {
		try {
			restaurantService.delete(restaurant);
			return 1;
		} catch (Exception e) {
			logger.error(e);
		}
		return 0;
	}

	public List<Restaurant> listarRestaurants() {
		try {
			return restaurantService.findAll();
		} catch (Exception e) {
			logger.error(e);
		}
		return null;
	}

	public List<Restaurant> obtenerRestaurantsPorUsuario(int usuarioId) {
		try {
			return restaurantService.obtenerRestaurantsPorUsuario(usuarioId);
		} catch (Exception e) {
			logger.error(e);
		}
		return null;
	}

	public Restaurant obtenerRestaurantPorId(int platoId) {
		try {
			return restaurantService.findById(platoId);
		} catch (Exception e) {
			logger.error(e);
			return null;
		}		
	}

	@Override
	public Restaurant autenticarRestaurant(String username, String pwd) {
		try {
			return restaurantService.autenticarRestaurant(username, pwd);
		} catch (Exception e) {
			logger.error(e);
			return null;
		}		
	}

}
